﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MarchEstate.Manager.BusinesEntity;
using MarchEstate.Manager.Dao.Cash;
using CoreFrame.Core.Aop;
using CoreFrame.Core.Transaction;

namespace MarchEstate.Manager.ObjectModel.Cash
{
    public class Account : AbstractAccount
    {
        private CashManagerDao cashDao = null;

        public Account()
        {
        }

        public override void InitDao()
        {
            base.InitDao();
            cashDao = NewDao<CashManagerDao>();
        }

        public override int[] GetTodayJoinNum(DateTime joindate)
        {
            int roomjoinNum = cashDao.GetJoinRoomNum(joindate);
            int carportjoinNum = cashDao.GetJoinCarportNum(joindate);
            return new int[] { roomjoinNum, carportjoinNum };
        }

        public override List<AbstractChargeMoney> GetAccountChargeList(string accountId)
        {
            return cashDao.GetAccountChargeList(accountId);
        }

        public override System.Data.DataTable GetAccountItemClassData(string accountId)
        {
            return cashDao.GetAccountItemClassData(accountId);
        }
        [AOP(typeof(AopTransaction))]
        public override bool SaveAccount(AbstractAccount account)
        {
            if (account.TotalFee != cashDao.GetTotalFee(null))
                throw new Exception("今天的交款数据发生了改变，请刷新当前页面数据！");
            //保存交款记录
            account.save();
            //反写结算表
            cashDao.ChargeMoneyAlterAccountId(account.AccountID);
            return true;
        }

        public override List<AbstractAccount> GetAccountList(DateTime bdate, DateTime edate)
        {
            return cashDao.GetAccountList(bdate, edate);
        }

        public override AbstractAccount GetAccount(string accountId)
        {
            return cashDao.GetAccount(accountId);
        }

        public override decimal GetTotalFee(string accountId)
        {
            return cashDao.GetTotalFee(accountId);
        }
    }
}
